package com.stagewebserver.webserver.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.stagewebserver.webserver.service.MenusService;
import com.stagecommon.common.pojo.Menus;
import com.stagecommon.common.pojo.RespBean;
import com.stagecommon.common.vo.MenusVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: yxl
 * @since: 2022-01-29
 **/
@RestController
@RequestMapping("/menus")
public class MenusController {

    @Autowired
    private MenusService menusService;

    @GetMapping("/getMenusList")
    public RespBean<List<MenusVo>> getMenusList(){
        return menusService.getMenusList();
    }

    @PostMapping("/getAllMenus")
    public RespBean<IPage<Menus>> getAllMenus(@RequestParam(defaultValue = "1") Integer currentPage,
                                              @RequestParam(defaultValue = "10") Integer size,
                                              @RequestBody Menus menus){
        return menusService.getMenus(currentPage, size, menus);
    }

    @PostMapping("/getMenusByLevel")
    public RespBean<List<Menus>> getMenusByLevel(@RequestBody Menus menus){
        return menusService.getMenusByLevel(menus.getMenuLevel());
    }

    @PostMapping("/addMenu")
    public RespBean addMenu(@RequestBody Menus menus){
        return menusService.addMenu(menus);
    }

    @PostMapping("/getMenuById")
    public RespBean<Menus> getMenuById(@RequestBody Menus menus){
        return menusService.getMenuById(menus.getMenuId());
    }

    @PostMapping("/deleteMenuById")
    public RespBean<Integer> deleteMenuById(@RequestBody Menus menus){
        return menusService.deleteMenuById(menus.getMenuId());
    }

    @PostMapping("/changeMenuById")
    public RespBean<Integer> changeMenuById(@RequestBody Menus menus){
        return menusService.updateMenuById(menus);
    }
}
